<?php

namespace app\admin\controller\daily;
use think\Db;
/**
 * 商品定时下架，用户设置商品有效期，有效期截至商品自动下架
 *
 * @icon fa fa-circle-o
 */
class Goodsoff
{
    
    /**
     * Goods模型对象
     * @var \app\admin\model\Goods
     */
    protected $model = null;

    public function _initialize()
    {
        $this->model = new \app\admin\model\goods\Goods();
    }
    
    public function index()
    {
        $condition['havetime'] = ['<',time()];
        $condition['status'] = ['not in',['2','9']];
        // dump($condition);
        $goods_list = Db::name('goods')->where($condition)->field('id,uid')->select();
        // dump($goods_list);exit;
        if($goods_list){
            $data = [
                'status' => 2,
                'reason' => '超出设置的商品有效期，如需继续出售请重新发布商品'
            ];
            foreach($goods_list as $k => $v){
                $result = Db::name('goods')->where(['id'=>$v['id']])->update($data);
            }
        }
    }


    

}
